/////
// appendix_figures.do
// This file creates the figures in the appendix except for Figure E.1 (see figure_e1.R).
// The input files are individual_level.dta and localauthority_level.dta. 
/////

/////
// Figure E.2: Ethnic group representation on the local council versus in the population.
/////	

* open local authority-level data
use "localauthority_level.dta", clear 

* create Figure E.2
twoway scatter percla percent_in_la, ///
	title("", size(medlarge)) ///
	ytitle("Percent of group on the council") ///
	xtitle("Percent of group in local authority population") ///
	ymtick(0(.1)1) xmtick(0(.1)1) ///
	msymbol(circle_hollow) mlcolor(black) jitter(4) legend(off) || lfit percla percent_in_la, lpattern(dash) lcolor(black)

/////
// Figure E.3: Percent of locality-years with ethnic groups in the council majority. 
/////

* open local authority-level data
use "localauthority_level.dta", clear 

* create a has_majority var 
egen has_majority = max(majority), by(territory_level year)

* filter to only majority == 1
keep territory_level year ethnicity la_clerk clerketh majority has_majority
keep if majority == 1 | /// keeps those la / years with a majority (most)
		(has_majority == 0 & la_clerk == 1 & clerketh == 1) /// keeps those la / years with a clerk but not majority

* rename ethnicity
rename ethnicity council_eth 
replace council_eth = "NO MAJORITY" if council_eth == ""

* create a factor version of council_eth
encode council_eth, gen(council_ethfac) 

* create Figure E.3
graph bar (percent), over(council_ethfac, sort(1) descending label(labsize(small) angle(30))) ///
	ytitle("Percent of locality-years") ylabel(0(5)20, nogrid) ymticks(0(1)20, nogrid) ///
	title("")  bar(1, color("82 82 82"))	

/////
// Figure E.4: Percent of ethnic group in the country and percent of locality-years in the majority. 
/////

* open local authority-level data
use "localauthority_level.dta", clear 

* n_ethmaj = number of la-years with ethnic group in the majority in entire country
bysort ethnicity: egen n_ethmaj = sum(majority)

* reduce to only territory_level / ethnicity
contract territory_level ethnicity latotal percent_in_la n_ethmaj
drop _freq
sort latotal territory_level

* create var for n eth in that la
bysort territory_level ethnicity: gen n_eth_la = _N
keep if (n_eth_la == 1 | (n_eth_la > 1 & percent_in_la > 0))
drop n_eth_la
gen n_ethgroup_la = latotal * percent_in_la

* create var for n eth in the country
bysort ethnicity: egen n_ethgroup_cntry = sum(n_ethgroup_la)

* contract to ethnic group-level
contract ethnicity n_ethmaj n_ethgroup_cntry
drop _freq

* perc in country
egen n_country = sum(n_ethgroup_cntry)
gen perc_ethgroup_cntry = (n_ethgroup_cntry / n_country)
replace perc_ethgroup_cntry = 0 if perc_ethgroup_cntry == .

* perc in majority
gen n_layears = (175 * 8)
gen perc_ethmaj = n_ethmaj / n_layears
sort perc_ethmaj

* create Figure E.4
scatter perc_ethgroup_cntry perc_ethmaj, ///
	jitter(5) msymbol(Oh) mcolor(black) ///
    xlabel(0(.05).25) xtick(0(.05).25) xtitle("Percent of ethnic group in country") ///
	ylabel(0(.05).25) ytick(0(.05).25) ytitle("Percent of locality-years in majority")

/////
// Figure E.5: "Stock" and "flow" of bureaucrats in localities in any given year.
/////

* open local authority-level data
use "localauthority_level.dta", clear 

* contract to la / year level
collapse (sum) working hired, by(territory_level year)

* stock -- i.e. number of bureaucrats working in a la / year
histogram working, frequency ///
	title("") ytitle("Frequency") xtitle("Number of bureaucrats working in a locality / year") ///
	xlabel(0(500)1500, nogrid) xtick(0(250)1500) color(gray) ///
	ylabel(0(500)1500, nogrid) ytick(0(250)1500) ///
	aspect(1) saving(stock, replace)
graph export "stock.pdf", replace 	

* flow -- i.e. number of bureaucrats hired in a la / year
histogram hired, frequency ///
	title("") ytitle("Frequency") xtitle("Number of bureaucrats hired in a locality / year") ///
	xlabel(0(200)1000, nogrid) xtick(0(100)1000) color(gray) ///
	ylabel(0(500)1500, nogrid) ytick(0(250)1500) ///
	aspect(1) saving(flow, replace)
graph export "flow.pdf", replace 	

* create Figure E.5
graph combine "stock" "flow", ycommon rows(1)

/////
// Figure F.1: Ethnic relationship between council majorities and clerks
/////

* open local authority-level data
use "localauthority_level.dta", clear 

* create a la / year id
egen layear_id = group(territory_level year)

* create a la id
egen la_id = group(territory_level)

* create the council maj eth var and fill for the entire la / year
gen councilmaj_eth = ""
replace councilmaj_eth = ethnicity if majority == 1 
xfill councilmaj_eth, i(layear_id)
replace councilmaj_eth = "NO MAJORITY" if councilmaj_eth == ""
	
* correct instances where there is more than one clerk
bysort territory_level year: egen n_clerk = sum(clerketh)
replace clerketh = 0 if clerketh == 1 & majority == 0 & n_clerk == 2
	
* create the clerk eth and fill for the entire la / years
gen clerk_eth = ""
replace clerk_eth = ethnicity if clerketh == 1
xfill clerk_eth, i(layear_id)
replace clerk_eth = "NO CLERK" if clerk_eth == ""
	
* contract to layear_id / territory_level / year / councilmaj_eth
contract layear_id la_id territory_level year councilmaj_eth clerk_eth
drop _freq
	
* create treatgroup_txt
gen treatgroup_txt = "No clerk" if clerk_eth == "NO CLERK"  // Localities with no clerk 
replace treatgroup_txt = "Non-co-ethnic clerk" if clerk_eth != councilmaj_eth & clerk_eth != "NO CLERK" // Localities with a clerk non-co-ethnic with the maj
replace treatgroup_txt = "Co-ethnic clerk" if clerk_eth == councilmaj_eth & clerk_eth != "NO CLERK" // Localities with a clerk co-ethnic with the maj
	
* create treatgroup
gen treatgroup = 0 if clerk_eth == "NO CLERK"  // Localities with no clerk 
replace treatgroup = -1 if clerk_eth != councilmaj_eth & clerk_eth != "NO CLERK" // Localities with a clerk non-co-ethnic with the maj
replace treatgroup = 1 if clerk_eth == councilmaj_eth & clerk_eth != "NO CLERK" // Localities with a clerk co-ethnic with the maj

* create custom pallete
capture program drop colorpalette_pvclr
program colorpalette_pvclr
      c_local P #f9061f%90, #808080%50, #00000%50
	  c_local I first, second, third
 end
colorpalette pvclr, nograph

* create Figure F.1 
panelview treatgroup, i(la_id) t(year) ///
	type(treat) mycolor(pvclr) ylabdist(10) ///
	xtitle("Year") ytitle("Local authorities") /// 
	legend(label(1 "Non-co-ethnic clerk") label(2 "No clerk") label(3 "Co-ethnic clerk")) 

/////
// Figure G.1: Clerk tenure in local authorities 
/////

* open individual-level data
use "individual_level.dta", clear 

* create a tenure variable = # of years that a clerk_id spends in a given local authority
keep if clerk == 1
sort territory_level clerk_id year 
by territory_level clerk_id: gen clerk_tenure = _n // 
by territory_level clerk_id: egen tenure_max = max(clerk_tenure)

* collapse 
collapse (median) tenure_max, by(clerk_id territory_level)
sort territory_level clerk_id

* create Figure G.1 
hist tenure_max, frequency discrete ///
	title("") ytitle("Frequency") xtitle("Number of years") ///
	yscale(range(0 300)) ylabel(0(100)300) ytick(0(100)300) ///
	xscale(range(1 8)) xlabel(1(1)8) xtick(1(1)8) ///
	bcolor(gray)

/////
// Figure H.1-H.5: Linear combinations iteratively dropping each local authority
/////

* open local authority-level data
use "localauthority_level.dta", clear 
est clear 

* create a la id
egen la_id = group(territory_level)

* define postfiles
tempname lincom1
postfile `lincom1' withoutla coeff sd using "dropla_lincom1_results.dta", replace
tempname lincom2
postfile `lincom2' withoutla coeff sd using "dropla_lincom2_results.dta", replace
tempname lincom3
postfile `lincom3' withoutla coeff sd using "dropla_lincom3_results.dta", replace
tempname lincom4
postfile `lincom4' withoutla coeff sd using "dropla_lincom4_results.dta", replace
tempname lincom5
postfile `lincom5' withoutla coeff sd using "dropla_lincom5_results.dta", replace

* loop over each local authority and iteratively leave one out
levelsof la_id, local(la)
foreach j of local la{
	
	* subset to NOT la j
	preserve
	keep if la_id != `j'
	di `j'

	* define depvar
	local depvar hired 
		
	* model with ethnic group-locality and year fixed effects 
	local indvar "c.majority##c.la_clerk##c.clerketh##c.perc`depvar'miss"
	quietly reghdfe perc`depvar' `indvar', absorb(TERETHid year) vce(cluster territory_level) // ethnic group-locality and year fixed effects 
			est store model_perc`depvar'_m1
			estadd local TERETH "Yes"
			estadd local ETHYEAR "No"
			estadd local year "Yes"
			estadd local TERYEAR "No"
			* calculate linear combinations and other stats 
				* no clerk and j is non co-ethnic with the council
				summarize perc`depvar' if majority == 0 & la_clerk == 0 & clerketh == 0 
				estadd scalar noclerk_majnoteth = r(mean)					
				* no clerk and j is co-ethnic with the council
				est restore model_perc`depvar'_m1
				lincom _b[majority]
				post `lincom1' (`j') (`r(estimate)') (`r(se)')
				* j is non-coethnic with the clerk and the council
				est restore model_perc`depvar'_m1
				lincom _b[la_clerk] 
				post `lincom2' (`j') (`r(estimate)') (`r(se)')	
				* j is non co-ethnic with the clerk, but co-ethnic with the council
				est restore model_perc`depvar'_m1
				lincom _b[majority] + _b[la_clerk] + _b[c.majority#c.la_clerk]
				post `lincom3' (`j') (`r(estimate)') (`r(se)')
				* j is co-ethnic with the clerk, but not with the council
				est restore model_perc`depvar'_m1
				lincom _b[la_clerk] + _b[clerketh]
				post `lincom4' (`j') (`r(estimate)') (`r(se)')
				* j is co-ethnic with the clerk and the council 
				est restore model_perc`depvar'_m1
				lincom _b[majority] + _b[la_clerk] + _b[c.majority#c.la_clerk] + _b[clerketh] + _b[c.majority#c.clerketh]
				post `lincom5' (`j') (`r(estimate)') (`r(se)')
				* outcome mean
				gen used_d`depvar' = e(sample)
				summarize perc`depvar' if used_d`depvar' == 1
				estadd scalar outcome_mean = r(mean)
				estfe model_perc`depvar'_m1, labels(TERETHid "Locality-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "Locality-year FE")
				drop used*
			
	* restore
	restore
	
}
postclose `lincom1'
postclose `lincom2'
postclose `lincom3'
postclose `lincom4'
postclose `lincom5'

* create Figure H.1 (lincom1)
use "dropla_lincom1_results.dta", clear

	* create 95% confidence intervals
	gen ci95_upper = coeff + 1.96*sd
	gen ci95_lower = coeff - 1.96*sd

	* gen sig 
	gen sig = 1 if ((ci95_upper > 0 & ci95_lower > 0) | (ci95_upper < 0 & ci95_lower < 0))
	replace sig = 0 if sig == .

	* plot 
	twoway (scatter coeff withoutla if sig == 1, msymbol(Oh) mcolor(black)) ///
		   (scatter coeff withoutla if sig == 0, msymbol(Oh) mcolor(black)) ///
		   (rcap ci95_lower ci95_upper withoutla if sig == 1, lcolor(black*.5)) ///
		   (rcap ci95_lower ci95_upper withoutla if sig == 0, lcolor(black*.5)), ///
		   yline(0, lpattern(dash) lcolor(black)) ///
		   yscale(range(-0.1 .4)) ylabel(-0.1(.1).4) ytick(-0.1(.1).4) ///
		   xscale(range(0 172)) xlabel(1(10)170, labsize(vsmall)) xtick(1(10)170) ///
		   title("No clerk and" "co-ethnic with the council", size(small)) ///
		   xtitle("Local authority dropped", size(small)) ytitle("Linear combination", size(small)) legend(off) ///
		   saving(dropla_lincom1, replace)

* create Figure H.2 (lincom2)
use "dropla_lincom2_results.dta", clear

	* create 95% confidence intervals
	gen ci95_upper = coeff + 1.96*sd
	gen ci95_lower = coeff - 1.96*sd

	* gen sig 
	gen sig = 1 if ((ci95_upper > 0 & ci95_lower > 0) | (ci95_upper < 0 & ci95_lower < 0))
	replace sig = 0 if sig == .

	* plot 
	twoway (scatter coeff withoutla if sig == 1, msymbol(Oh) mcolor(black)) ///
		   (scatter coeff withoutla if sig == 0, msymbol(Oh) mcolor(black)) ///
		   (rcap ci95_lower ci95_upper withoutla if sig == 1, lcolor(black*.5)) ///
		   (rcap ci95_lower ci95_upper withoutla if sig == 0, lcolor(black*.5)), ///
		   yline(0, lpattern(dash) lcolor(black)) ///
		   yscale(range(-0.005 .001)) ylabel(-0.005(.001).001) ytick(-0.005(.001).001) ///
		   xscale(range(0 172)) xlabel(1(10)170, labsize(vsmall)) xtick(1(10)170) ///
		   title("Non-co-ethnic clerk and" "non-co-ethnic with the council", size(small)) ///
		   xtitle("Local authority dropped", size(small)) ytitle("Linear combination", size(small)) legend(off) ///
		   saving(dropla_lincom2, replace)

* create Figure H.3 (lincom3)
use "dropla_lincom3_results.dta", clear

	* create 95% confidence intervals
	gen ci95_upper = coeff + 1.96*sd
	gen ci95_lower = coeff - 1.96*sd

	* gen sig 
	gen sig = 1 if ((ci95_upper > 0 & ci95_lower > 0) | (ci95_upper < 0 & ci95_lower < 0))
	replace sig = 0 if sig == .

	* plot 
	twoway (scatter coeff withoutla if sig == 1, msymbol(Oh) mcolor(black)) ///
		   (scatter coeff withoutla if sig == 0, msymbol(Oh) mcolor(black)) ///
		   (rcap ci95_lower ci95_upper withoutla if sig == 1, lcolor(black*.5)) ///
		   (rcap ci95_lower ci95_upper withoutla if sig == 0, lcolor(black*.5)), ///
		   yline(0, lpattern(dash) lcolor(black)) ///
		   yscale(range(.2 .2)) ylabel(-.2(.1).2) ytick(-.2(.1).2) ///
		   xscale(range(0 172)) xlabel(1(10)170, labsize(vsmall)) xtick(1(10)170) ///
		   title("Non-co-ethnic clerk and" "co-ethnic with the council", size(small)) ///
		   xtitle("Local authority dropped", size(small)) ytitle("Linear combination", size(small)) legend(off) ///
		   saving(dropla_lincom3, replace)

* create Figure H.4 (lincom4)
use "dropla_lincom4_results.dta", clear

	* create 95% confidence intervals
	gen ci95_upper = coeff + 1.96*sd
	gen ci95_lower = coeff - 1.96*sd

	* gen sig 
	gen sig = 1 if ((ci95_upper > 0 & ci95_lower > 0) | (ci95_upper < 0 & ci95_lower < 0))
	replace sig = 0 if sig == .

	* plot 
	twoway (scatter coeff withoutla if sig == 1, msymbol(Oh) mcolor(black)) ///
		   (scatter coeff withoutla if sig == 0, msymbol(Oh) mcolor(black)) ///
		   (rcap ci95_lower ci95_upper withoutla if sig == 1, lcolor(black*.5)) ///
		   (rcap ci95_lower ci95_upper withoutla if sig == 0, lcolor(black*.5)), ///
		   yline(0, lpattern(dash) lcolor(black)) ///
		   yscale(range(-.05 .25)) ylabel(-.05(.1).25) ytick(-.05(.1).25) ///
		   xscale(range(0 172)) xlabel(1(10)170, labsize(vsmall)) xtick(1(10)170) ///
		   title("Co-ethnic clerk and" "non-co-ethnic with the council", size(small)) ///
		   xtitle("Local authority dropped", size(small)) ytitle("Linear combination", size(small)) legend(off) ///
		   saving(dropla_lincom4, replace)

* create Figure H.5 (lincom5)
use "dropla_lincom5_results.dta", clear

	* create 95% confidence intervals
	gen ci95_upper = coeff + 1.96*sd
	gen ci95_lower = coeff - 1.96*sd

	* gen sig 
	gen sig = 1 if ((ci95_upper > 0 & ci95_lower > 0) | (ci95_upper < 0 & ci95_lower < 0))
	replace sig = 0 if sig == .

	* plot 
	twoway (scatter coeff withoutla if sig == 1, msymbol(Oh) mcolor(black)) ///
		   (scatter coeff withoutla if sig == 0, msymbol(Oh) mcolor(black)) ///
		   (rcap ci95_lower ci95_upper withoutla if sig == 1, lcolor(black*.5)) ///
		   (rcap ci95_lower ci95_upper withoutla if sig == 0, lcolor(black*.5)), ///
		   yline(0, lpattern(dash) lcolor(black)) ///
		   yscale(range(-.05 .45)) ylabel(-.05(.1).45) ytick(-.05(.1).45) ///
		   xscale(range(0 172)) xlabel(1(10)170, labsize(vsmall)) xtick(1(10)170) ///
		   title("Co-ethnic clerk and" "co-ethnic with the council", size(small)) ///
		   xtitle("Local authority dropped", size(small)) ytitle("Linear combination", size(small)) legend(off) ///
		   saving(dropla_lincom5, replace)

/////
// Figure H.6: Linear combinations iteratively dropping each ethnicity. 
/////

* open local authority-level data
use "localauthority_level.dta", clear 
est clear 

* create a la id
egen eth_id = group(ethnicity)

* define postfile
tempname lincom1
postfile `lincom1' withouteth coeff sd using "dropeth_lincom1_results.dta", replace
tempname lincom2
postfile `lincom2' withouteth coeff sd using "dropeth_lincom2_results.dta", replace
tempname lincom3
postfile `lincom3' withouteth coeff sd using "dropeth_lincom3_results.dta", replace
tempname lincom4
postfile `lincom4' withouteth coeff sd using "dropeth_lincom4_results.dta", replace
tempname lincom5
postfile `lincom5' withouteth coeff sd using "dropeth_lincom5_results.dta", replace

* loop over each ethnicity and iteratively leave one out
levelsof eth_id, local(eth_id)
foreach j of local eth_id{
	
	* subset to NOT ethnicity j
	preserve
	keep if eth_id != `j'
	di `j'

	* define dependent variable
	local depvar hired 
		
	* models with ethnic group-locality and year fixed effects 
		local indvar "c.majority##c.la_clerk##c.clerketh##c.perc`depvar'miss"
		quietly reghdfe perc`depvar' `indvar', absorb(TERETHid year) vce(cluster territory_level) // ethnic group-locality and year fixed effects 
			est store model_perc`depvar'_m1
			estadd local TERETH "Yes"
			estadd local ETHYEAR "No"
			estadd local year "Yes"
			estadd local TERYEAR "No"
			* calculate linear combinations 
				* no clerk and j is non co-ethnic with the council
				summarize perc`depvar' if majority == 0 & la_clerk == 0 & clerketh == 0 
				estadd scalar noclerk_majnoteth = r(mean)				
				* no clerk and j is co-ethnic with the council
				est restore model_perc`depvar'_m1
				lincom _b[majority]
				post `lincom1' (`j') (`r(estimate)') (`r(se)')
				* j is non-coethnic with the clerk and the council
				est restore model_perc`depvar'_m1
				lincom _b[la_clerk] 
				post `lincom2' (`j') (`r(estimate)') (`r(se)')
				* j is non co-ethnic with the clerk, but co-ethnic with the council
				est restore model_perc`depvar'_m1
				lincom _b[majority] + _b[la_clerk] + _b[c.majority#c.la_clerk]
				post `lincom3' (`j') (`r(estimate)') (`r(se)')
				* j is co-ethnic with the clerk, but not with the council
				est restore model_perc`depvar'_m1
				lincom _b[la_clerk] + _b[clerketh]
				post `lincom4' (`j') (`r(estimate)') (`r(se)')
				* j is co-ethnic with the clerk and the council 
				est restore model_perc`depvar'_m1
				lincom _b[majority] + _b[la_clerk] + _b[c.majority#c.la_clerk] + _b[clerketh] + _b[c.majority#c.clerketh]
				post `lincom5' (`j') (`r(estimate)') (`r(se)')
				* outcome mean
				gen used_d`depvar' = e(sample)
				summarize perc`depvar' if used_d`depvar' == 1
				estadd scalar outcome_mean = r(mean)
				estfe model_perc`depvar'_m1, labels(TERETHid "Locality-ethnicity FE" year "Year FE" ETHYEARid "Ethnicity-year FE" TERYEARid "Locality-year FE")
				drop used*

	* restore
	restore
		
}
postclose `lincom1'
postclose `lincom2'
postclose `lincom3'
postclose `lincom4'
postclose `lincom5'
 
* create plot for lincom1
use "dropeth_lincom1_results.dta", clear

	* ethnicity 
	label define ethnicity 1 "BORANA" 2 "EMBU" 3 "KALENJIN" 4 "KAMBA" ///
						   5 "KIKUYU" 6 "KISII" 7 "KURIA" 8 "LUHYA" ///
						   9 "LUO" 10 "MAASAI" 11 "MERU" 12 "MIJIKENDA" ///
						   13 "SAMBURU" 14 "SOMALI" 15 "SWAHILI" 16 "TAITA" ///
						   17 "TAVETA" 18 "TURKANA"
	label values withouteth ethnicity

	* create 95% confidence intervals
	gen ci95_upper = coeff + 1.96*sd
	gen ci95_lower = coeff - 1.96*sd

	* gen sig 
	gen sig = 1 if ((ci95_upper > 0 & ci95_lower > 0) | (ci95_upper < 0 & ci95_lower < 0))
	replace sig = 0 if sig == .

	* plot 
	twoway (scatter coeff withouteth if sig == 1, msymbol(Oh) mcolor(black)) ///
		   (scatter coeff withouteth if sig == 0, msymbol(Oh) mcolor(black)) ///
		   (rcap ci95_lower ci95_upper withouteth if sig == 1, lcolor(black*.5)) ///
		   (rcap ci95_lower ci95_upper withouteth if sig == 0, lcolor(black*.5)), ///
		   yline(0, lpattern(dash) lcolor(black)) ///
		   yscale(range(-0.1 .4)) ylabel(-0.1(.1).4, labsize(2)) ytick(-0.1(.1).4) ///
		   xscale(range(0 19)) xlabel(1(1)18, valuelabel angle(12) labsize(1)) xtick(1(1)18) ///
		   title("No clerk and" "co-ethnic with the council", size(small)) ///
		   xtitle("Ethnicity dropped", size(small)) ytitle("Linear combination", size(small)) legend(off) ///
		   aspect(1) saving(dropeth_lincom1, replace)

* create plot for lincom2
use "dropeth_lincom2_results.dta", clear

	* ethnicity 
	label define ethnicity 1 "BORANA" 2 "EMBU" 3 "KALENJIN" 4 "KAMBA" ///
						   5 "KIKUYU" 6 "KISII" 7 "KURIA" 8 "LUHYA" ///
						   9 "LUO" 10 "MAASAI" 11 "MERU" 12 "MIJIKENDA" ///
						   13 "SAMBURU" 14 "SOMALI" 15 "SWAHILI" 16 "TAITA" ///
						   17 "TAVETA" 18 "TURKANA"
	label values withouteth ethnicity

	* create 95% confidence intervals
	gen ci95_upper = coeff + 1.96*sd
	gen ci95_lower = coeff - 1.96*sd

	* gen sig 
	gen sig = 1 if ((ci95_upper > 0 & ci95_lower > 0) | (ci95_upper < 0 & ci95_lower < 0))
	replace sig = 0 if sig == .

	* plot 
	twoway (scatter coeff withouteth if sig == 1, msymbol(Oh) mcolor(black)) ///
		   (scatter coeff withouteth if sig == 0, msymbol(Oh) mcolor(black)) ///
		   (rcap ci95_lower ci95_upper withouteth if sig == 1, lcolor(black*.5)) ///
		   (rcap ci95_lower ci95_upper withouteth if sig == 0, lcolor(black*.5)), ///
		   yline(0, lpattern(dash) lcolor(black)) ///
		   yscale(range(-0.005 .001)) ylabel(-0.005(.001).001, labsize(2)) ytick(-0.005(.001).001) ///
		   xscale(range(0 19)) xlabel(1(1)18, valuelabel angle(12) labsize(1)) xtick(1(1)18) ///
		   title("Non-co-ethnic with the clerk and" "non-co-ethnic with the council", size(small)) ///
		   xtitle("Ethnicity dropped", size(small)) ytitle("Linear combination", size(small)) legend(off) ///
		   aspect(1) saving(dropeth_lincom2, replace)

* create plot for lincom3
use "dropeth_lincom3_results.dta", clear

	* ethnicity 
	label define ethnicity 1 "BORANA" 2 "EMBU" 3 "KALENJIN" 4 "KAMBA" ///
						   5 "KIKUYU" 6 "KISII" 7 "KURIA" 8 "LUHYA" ///
						   9 "LUO" 10 "MAASAI" 11 "MERU" 12 "MIJIKENDA" ///
						   13 "SAMBURU" 14 "SOMALI" 15 "SWAHILI" 16 "TAITA" ///
						   17 "TAVETA" 18 "TURKANA"
	label values withouteth ethnicity

	* create 95% confidence intervals
	gen ci95_upper = coeff + 1.96*sd
	gen ci95_lower = coeff - 1.96*sd

	* gen sig 
	gen sig = 1 if ((ci95_upper > 0 & ci95_lower > 0) | (ci95_upper < 0 & ci95_lower < 0))
	replace sig = 0 if sig == .

	* plot 
	twoway (scatter coeff withouteth if sig == 1, msymbol(Oh) mcolor(black)) ///
		   (scatter coeff withouteth if sig == 0, msymbol(Oh) mcolor(black)) ///
		   (rcap ci95_lower ci95_upper withouteth if sig == 1, lcolor(black*.5)) ///
		   (rcap ci95_lower ci95_upper withouteth if sig == 0, lcolor(black*.5)), ///
		   yline(0, lpattern(dash) lcolor(black)) ///
		   yscale(range(.2 .2)) ylabel(-.2(.1).2, labsize(2)) ytick(-.2(.1).2) ///
		   xscale(range(0 19)) xlabel(1(1)18, valuelabel angle(12) labsize(1)) xtick(1(1)18) ///
		   title("Non-co-ethnic with the clerk and" "co-ethnic with the council", size(small)) ///
		   xtitle("Ethnicity dropped", size(small)) ytitle("Linear combination", size(small)) legend(off) ///
		   aspect(1) saving(dropeth_lincom3, replace)

* create plot for lincom4
use "dropeth_lincom4_results.dta", clear

	* ethnicity 
	label define ethnicity 1 "BORANA" 2 "EMBU" 3 "KALENJIN" 4 "KAMBA" ///
						   5 "KIKUYU" 6 "KISII" 7 "KURIA" 8 "LUHYA" ///
						   9 "LUO" 10 "MAASAI" 11 "MERU" 12 "MIJIKENDA" ///
						   13 "SAMBURU" 14 "SOMALI" 15 "SWAHILI" 16 "TAITA" ///
						   17 "TAVETA" 18 "TURKANA"
	label values withouteth ethnicity

	* create 95% confidence intervals
	gen ci95_upper = coeff + 1.96*sd
	gen ci95_lower = coeff - 1.96*sd

	* gen sig 
	gen sig = 1 if ((ci95_upper > 0 & ci95_lower > 0) | (ci95_upper < 0 & ci95_lower < 0))
	replace sig = 0 if sig == .

	* plot 
	twoway (scatter coeff withouteth if sig == 1, msymbol(Oh) mcolor(black)) ///
		   (scatter coeff withouteth if sig == 0, msymbol(Oh) mcolor(black)) ///
		   (rcap ci95_lower ci95_upper withouteth if sig == 1, lcolor(black*.5)) ///
		   (rcap ci95_lower ci95_upper withouteth if sig == 0, lcolor(black*.5)), ///
		   yline(0, lpattern(dash) lcolor(black)) ///
		   yscale(range(-.05 .25)) ylabel(-.05(.1).25, labsize(2)) ytick(-.05(.1).25) ///
		   xscale(range(0 19)) xlabel(1(1)18, valuelabel angle(12) labsize(1)) xtick(1(1)18) ///
		   title("Co-ethnic with the clerk and" "non-co-ethnic with the council", size(small)) ///
		   xtitle("Ethnicity dropped", size(small)) ytitle("Linear combination", size(small)) legend(off) ///
		   aspect(1) saving(dropeth_lincom4, replace)

* create plot for lincom5
use "dropeth_lincom5_results.dta", clear

	* ethnicity 
	label define ethnicity 1 "BORANA" 2 "EMBU" 3 "KALENJIN" 4 "KAMBA" ///
						   5 "KIKUYU" 6 "KISII" 7 "KURIA" 8 "LUHYA" ///
						   9 "LUO" 10 "MAASAI" 11 "MERU" 12 "MIJIKENDA" ///
						   13 "SAMBURU" 14 "SOMALI" 15 "SWAHILI" 16 "TAITA" ///
						   17 "TAVETA" 18 "TURKANA"
	label values withouteth ethnicity

	* create 95% confidence intervals
	gen ci95_upper = coeff + 1.96*sd
	gen ci95_lower = coeff - 1.96*sd

	* gen sig 
	gen sig = 1 if ((ci95_upper > 0 & ci95_lower > 0) | (ci95_upper < 0 & ci95_lower < 0))
	replace sig = 0 if sig == .

	* plot 
	twoway (scatter coeff withouteth if sig == 1, msymbol(Oh) mcolor(black)) ///
		   (scatter coeff withouteth if sig == 0, msymbol(Oh) mcolor(black)) ///
		   (rcap ci95_lower ci95_upper withouteth if sig == 1, lcolor(black*.5)) ///
		   (rcap ci95_lower ci95_upper withouteth if sig == 0, lcolor(black*.5)), ///
		   yline(0, lpattern(dash) lcolor(black)) ///
		   yscale(range(-.05 .45)) ylabel(-.05(.1).45, labsize(2)) ytick(-.05(.1).45) ///
		   xscale(range(0 19)) xlabel(1(1)18, valuelabel angle(12) labsize(1)) xtick(1(1)18) ///
		   title("Co-ethnic with the clerk and" "co-ethnic with the council", size(small)) ///
		   xtitle("Ethnicity dropped", size(small)) ytitle("Linear combination", size(small)) legend(off) ///
		   aspect(1) saving(dropeth_lincom5, replace)

* plot the combine versions

	* create rows separately
	graph combine "dropeth_lincom1" "dropeth_lincom2" "dropeth_lincom3", ///
		rows(1) xcommon name(row1, replace)
	graph combine "dropeth_lincom4" "dropeth_lincom5", ///
		rows(1) xcommon name(row2, replace)

	* combine the rows
	graph combine row1 row2, cols(1) xcommon


